package my.edu.model.commodity.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import my.edu.common.validate.groups.Insert;
import my.edu.common.domain.Response;
import my.edu.model.commodity.entity.dto.ProductCategoryDTO;
import my.edu.model.commodity.service.IProductCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/materialCategory")
@RestController
@Tag(name = "商品类别接口")
@Validated
public class ProductCategoryController {
    @Autowired
    private IProductCategoryService productCategoryService;

    @GetMapping("/getMaterialCategoryTree")
    @Operation(summary = "获取商品类别列表的树")
    public Response getList(Long id){
        return Response.success(productCategoryService.listAll(id));
    }

//    @GetMapping
//    @Operation(summary = "获取商品类别列表名字")
//    @RequiresPermissions("product:get")
//    public Response getListOnly(){
//        return Response.success(productCategoryService.listAllOnly());
//    }




    @PutMapping
    @Operation(summary = "新增商品类别")
    @RequiresPermissions("product:save")
    public Response save( @Validated(Insert.class) @RequestBody ProductCategoryDTO productCategoryDTO){
        productCategoryService.saveNew(productCategoryDTO);
        return Response.success();
    }
    @PostMapping("/update")
    @Operation(summary = "修改商品类别")
    @RequiresPermissions("product:update")
    public Response update(@Validated @RequestBody ProductCategoryDTO productCategoryDTO){
        productCategoryService.updateByDTO(productCategoryDTO);
        return Response.success();
    }

    @GetMapping("/one")
    @RequiresPermissions("product:get")
    @Operation(summary = "根据编号获取类别信息")
    public Response getProductCategoryById( @NotNull(message = "id不能为空") Long id) {
        return Response.success(productCategoryService.getById(id));
    }

}
